package com.gph.saviorframework.activiti.extension.identity;

import com.gph.saviorframework.security.service.RoleService;
import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.Picture;
import org.activiti.engine.identity.User;
import org.activiti.engine.identity.UserQuery;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.UserQueryImpl;
import org.activiti.engine.impl.persistence.AbstractManager;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.activiti.engine.impl.persistence.entity.IdentityInfoEntity;
import org.activiti.engine.impl.persistence.entity.UserIdentityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
public class CustomUserEntityManager extends AbstractManager implements UserIdentityManager {

	@Autowired
	RoleService roleService;

	public User createNewUser(String userId) {
		return null;
	}

	public void insertUser(User user) {
		
	}

	public void updateUser(User updatedUser) {
		
	}

	public User findUserById(String userId) {
		return null;
	}

	public void deleteUser(String userId) {
		
	}

	public List<User> findUserByQueryCriteria(UserQueryImpl query, Page page) {
		return null;
	}

	public long findUserCountByQueryCriteria(UserQueryImpl query) {
		return 0;
	}

	public List<Group> findGroupsByUser(String userId) {
		List<Group> groups = new ArrayList<Group>();
		List<Map<String, Object>> roles = roleService.findByUser(userId);
		for(Map<String, Object> role : roles) {
			GroupEntity ge = new GroupEntity();
			ge.setId(role.get("id").toString());
			ge.setName(role.get("name").toString());
			groups.add(ge);
		}
		return groups;
	}

	public UserQuery createNewUserQuery() {
		return null;
	}

	public IdentityInfoEntity findUserInfoByUserIdAndKey(String userId,
			String key) {
		return null;
	}

	public List<String> findUserInfoKeysByUserIdAndType(String userId,
			String type) {
		return null;
	}

	public Boolean checkPassword(String userId, String password) {
		return null;
	}

	public List<User> findPotentialStarterUsers(String proceDefId) {
		return null;
	}

	public List<User> findUsersByNativeQuery(Map<String, Object> parameterMap,
			int firstResult, int maxResults) {
		return null;
	}

	public long findUserCountByNativeQuery(Map<String, Object> parameterMap) {
		return 0;
	}

	public boolean isNewUser(User user) {
		return false;
	}

	public Picture getUserPicture(String userId) {
		return null;
	}

	public void setUserPicture(String userId, Picture picture) {
		
	}

}
